package persistence.serialization;

import java.io.IOException;

import core.ILoader;
import core.ISaver;
import core.SerializableLoader;
import core.SerializableSaver;
import core.exception.SaveException;
import persistence.AllDAO;

/**
 * AllDAO for serialization persistence
 * @author Sabrina
 *
 */
public class SerialAllDAO implements AllDAO {

	/**
	 * Creates a DBAllDAO
	 */
	public SerialAllDAO()
	{
		
	}
	
	/**
	 * @inheritDoc
	 */
	@Override
	public void save() throws SaveException {
		ISaver saver = new SerializableSaver();
		try {
			saver.save();
		} catch (IOException e) {
			throw new SaveException(e.getMessage());
		}
	}

	/**
	 * @inheritDoc
	 */
	@Override
	public void load() throws SaveException {
		ILoader loader = new SerializableLoader();
		try {
			loader.load();
		} 
		catch (IOException e) {
			//ignore it, there's not a file right now
		}
		catch (ClassNotFoundException e) {
			throw new SaveException(e.getMessage());
		}

	}

}
